// ABPAEngine.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "TlsNative.h"
//#include "PostOffice.h"

/**
 * This DLL is loaded by "Loader" only inside processes
 * that should be monitored, and it starts all hooking
 * mechanism.
 * This DLL can have dependencies, which will be loaded
 * together with it.
 */

#ifdef _MANAGED
#pragma managed(push, off)
#endif

void StartAbpaEngine(void);
void StopAbpaEngine(void);


platform::TlsFlag s_internalModeFlag;


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		s_internalModeFlag.initSlot();
		s_internalModeFlag.initThreadValue(false);
		StartAbpaEngine();
		break;

	case DLL_THREAD_ATTACH:
		s_internalModeFlag.initThreadValue(false);
		break;

	case DLL_THREAD_DETACH:
		s_internalModeFlag.releaseThreadValue();
		break;

	case DLL_PROCESS_DETACH:
		StopAbpaEngine();
		s_internalModeFlag.releaseSlot();
		break;
	}
	return TRUE;
}


// Forward declarations

void InstallHooks(void);
void RestoreHooks(void);

void StartAbpaEngine(void) {
	InstallHooks();
}

void StopAbpaEngine(void) {
	RestoreHooks();
}


#ifdef _MANAGED
#pragma managed(pop)
#endif

